<template>
    <el-form
        ref="ruleRef"
        :model="state.ruleForm"
        :rules="state.rules"
        label-position="top"
    >
        <el-form-item label="审核状态" prop="sign">
            <el-radio-group v-model="state.ruleForm.sign">
                <el-radio :value="true">同意</el-radio>
                <el-radio :value="false">驳回</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="note">
            <el-input
                v-model.trim="state.ruleForm.note"
                type="textarea"
                maxlength="100"
                :autosize="{ minRows: 2 }"
                clearable
                show-word-limit
                placeholder="请输入备注"
            />
        </el-form-item>
        <el-form-item>
            <el-button
                type="primary"
                :loading="form_loading"
                class="w-100% mt-10 mb--10"
                @click="submitForm(ruleRef)"
            >
                确认
            </el-button>
        </el-form-item>
    </el-form>
</template>

<script setup>
import { reactive, ref, inject } from "vue";
import { examineOrderRefund } from "@/apis/order/order";

const emit = defineEmits(["success"]);
const props = defineProps({
    sid: {
        type: String,
        required: true,
    },
});

const $message = inject("$message");

const form_loading = ref(false);
const ruleRef = ref(null);
const state = reactive({
    ruleForm: {
        sign: true,
        note: null,
    },
    rules: {
        sign: [{ required: true, message: "请选择审核状态", trigger: "blur" }],
    },
    driverOptions: [],
});

// 后台订单补款
const submitForm = (formEl) => {
    if (!formEl) return;
    formEl.validate(async (valid, fields) => {
        if (valid) {
            form_loading.value = true;
            let res = await examineOrderRefund({
                ...state.ruleForm,
                sid: props.sid,
            });
            form_loading.value = false;
            if (res.data.code == 200) {
                $message({
                    message: "操作成功",
                    type: "success",
                });
                emit("success");
            } else {
                $message({ message: res.data.msg, type: "error" });
            }
        }
    });
};
</script>
